home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / gcc / libnix.lha / gnu / lib / libnix / sources.lha / detach / bcback12.S < prev    next >
Encoding:
Text File  |  1994-06-11  |  4.5 KB  |  288 lines

  1. | auto-detaching baserelative startup code for gcc v2.3.3
  2. | (c) by M.Fleischer and G.Nikl Fri May 27 20:33 1994
  3. | No real bugs known
  4.  
  5. | some specific defines
  6.  
  7. _LVOForbid    =    -132
  8. _LVOPermit    =    -138
  9. _LVOAllocMem    =    -198
  10. _LVOFreeMem    =    -210
  11. _LVOAddTail    =    -246
  12. _LVOFindTask    =    -294
  13. _LVOGetMsg    =    -372
  14. _LVOReplyMsg    =    -378
  15. _LVOWaitPort    =    -384
  16. _LVOCloseLibrary =    -414
  17. _LVOOpenLibrary    =    -552
  18.  
  19. _LVOLock    =     -84
  20. _LVOUnlock    =     -90
  21. _LVOCurrentDir    =    -126
  22. _LVOCreateProc    =    -138
  23.  
  24. tc_MemEntry    =      74
  25. pr_MsgPort    =      92
  26. pr_CLI        =     172
  27.  
  28. cli_Module    =      60
  29.  
  30. SHARED_LOCK    =      -2
  31.  
  32. RETURN_OK    =       0
  33. RETURN_FAIL    =      20
  34.  
  35. | public symbols
  36.  
  37.         .globl    ___subexit
  38.         .globl    _geta4
  39.  
  40.         .text
  41.  
  42. | first entry - init some vars, check for cli or wb start
  43.  
  44. start:        movel    a0,d3
  45.  
  46.         jbsr    _geta4
  47.  
  48.         lea    a4@(__edata:W),a0
  49.         lea    a4@(__end:W),a1
  50.         jra    clrbss2
  51. clrbss1:    clrl    a0@+
  52. clrbss2:    cmpl    a1,a0
  53.         bcss    clrbss1
  54.  
  55.         movel    sp,a4@(_SaveSP:W)
  56.         movel    4:W,a6
  57.         movel    a6,a4@(_SysBase:W)
  58.  
  59.         subal    a1,a1
  60.         jsr    a6@(_LVOFindTask:W)
  61.         movel    d0,a3
  62.  
  63.         movel    a4@(_cmdLine:W),d0
  64.         exg    d0,d3
  65.         bnes    fromCLI
  66.  
  67.         tstl    a3@(pr_CLI:W)
  68.         exg    d0,d3
  69.         bne    Detach
  70.  
  71. | wb start - get wbmsg
  72.  
  73. fromWB:        lea    a3@(pr_MsgPort:W),a0
  74.         jsr    a6@(_LVOWaitPort:W)
  75.         lea    a3@(pr_MsgPort:W),a0
  76.         jsr    a6@(_LVOGetMsg:W)
  77.         movel    d0,a4@(__WBenchMsg:W)
  78.  
  79. | common - open all libs
  80.  
  81. fromCLI:    tstl    _cmdLine
  82.         beqs    skip1
  83.  
  84.         moveq    #RETURN_FAIL,d7
  85.         lea    a4@(___dosname:W),a1
  86.         moveq    #33,d0
  87.         jsr    a6@(_LVOOpenLibrary:W)
  88.         movel    d0,a4@(_DOSBase:W)
  89.         beq    nolib
  90.         movel    d0,a6
  91.         lea    a4@(_curDir:W),a2
  92.         movel    a2@,d1
  93.         jsr    a6@(_LVOCurrentDir:W)
  94.         movel    d0,a2@
  95.  
  96. | call __submain()
  97.  
  98. skip1:        movel    d3,a4@(___commandline:W)
  99.         jmp    ___submain
  100.  
  101. | __subexit() entry - get return val, restore stackptr
  102.  
  103. ___subexit:    movel    sp@(4:W),d0
  104.         movel    a4@(_SaveSP:W),sp
  105.  
  106. | cleanup - close lib, reply wbmsg
  107.  
  108.         movel    a4@(_SysBase:W),a6
  109.         tstl    a4@(_cmdLine:W)
  110.         beqs    nolib
  111.  
  112.         movel    a6,a5
  113.         movel    a4@(_DOSBase:W),a6
  114.         movel    a4@(_curDir:W),d1
  115.         jsr    a6@(_LVOCurrentDir:W)
  116.         movel    d0,d1
  117.         jsr    a6@(_LVOUnlock:W)
  118.         movel    a6,a1
  119.         movel    a5,a6
  120.         jsr    a6@(_LVOCloseLibrary:W)
  121.  
  122. nolib:        movel    a4@(__WBenchMsg:W),d2
  123.         beqs    todos
  124.         jsr    a6@(_LVOForbid:W)
  125.         movel    d2,a1
  126.         jsr    a6@(_LVOReplyMsg:W)
  127.  
  128. todos:        movel    d7,d0
  129.         rts
  130.  
  131. | get baseptr
  132.  
  133. _geta4:        lea    ___a4_init,a4
  134.         rts
  135.  
  136. | detach the process from the shell task
  137.  
  138. Detach:        lea    a4@(___dosname:W),a1
  139.         moveq    #33,d0
  140.         jsr    a6@(_LVOOpenLibrary:W)
  141.  
  142. | need a private DOSBase !!!
  143.  
  144.         movel    d0,d6
  145.         beq    nodos
  146.  
  147.         movel    a3@(pr_CLI:W),a3
  148.         addal    a3,a3
  149.         addal    a3,a3
  150.         lea    a3@(cli_Module:W),a3
  151.  
  152. | length of the commandline
  153.  
  154.         movel    d3,a0
  155.         moveq    #7,d0
  156. arglen:        addql    #1,d0
  157.         cmpb    #10,a0@+
  158.         bnes    arglen
  159.         moveq    #-8,d2
  160.         andl    d0,d2
  161.  
  162. | number of hunks
  163.  
  164.         moveq    #24,d5
  165.         movel    a3@,a0
  166. cntsegs:    addal    a0,a0
  167.         addal    a0,a0
  168.         addql    #8,d5
  169.         movel    a0@,d0
  170.         movel    d0,a0
  171.         bnes    cntsegs
  172.         addl    d2,d5
  173.  
  174. | needed memory for memlist and commandline
  175.  
  176.         movel    d5,d0
  177.         moveq    #1,d1
  178.         swap    d1
  179.         jsr    a6@(_LVOAllocMem:W)
  180.         movel    d0,a2
  181.         movel    a2,d0
  182.         beq    nomem
  183.  
  184. | setup our memlist - first hunks, then cmdLine
  185.  
  186.         lea    a2@(16:W),a1
  187.         movel    a3@,a0
  188. addsegs:    addal    a0,a0
  189.         addal    a0,a0
  190.         movel    a0@-,d0
  191.         movel    a0,a1@+
  192.         movel    d0,a1@+
  193.         addqw    #1,a2@(14:W)
  194.         movel    a0@(4:W),d0
  195.         movel    d0,a0
  196.         bnes    addsegs
  197.  
  198.         lea    a1@(8:W),a0
  199.         movel    a0,a1@+
  200.         movel    d2,a1@+
  201.         addqw    #1,a2@(14:W)
  202.  
  203. | new commandline for later use
  204.  
  205.         movel    a1,a4@(_cmdLine:W)
  206.         movel    d3,a0
  207. cpyarg:        moveb    a0@+,a1@
  208.         cmpb    #10,a1@+
  209.         bnes    cpyarg
  210.  
  211. | new currentdir lock for background process
  212.  
  213.         clrl    sp@-
  214.         movel    sp,d1
  215.         moveq    #SHARED_LOCK,d2
  216.         exg    d6,a6
  217.         jsr    a6@(_LVOLock:W)
  218.         exg    d6,a6
  219.         movel    d0,a4@(_curDir:W)
  220.         addqw    #4,sp
  221.  
  222. | create process with disabled multitasking !!!
  223.  
  224.         jsr    a6@(_LVOForbid:W)
  225.  
  226.         movel    a4@(__procname:W),d1
  227.         movel    a4@(__priority:W),d2
  228.         movel    a3@,d3
  229.         movel    a4@(__stack:W),d4
  230.         exg    d6,a6
  231.         jsr    a6@(_LVOCreateProc:W)
  232.         exg    d6,a6
  233.         movel    d0,a5
  234.         movel    a5,d0
  235.         beqs    noproc
  236.  
  237. | insert memlist to free all memory at process end
  238.  
  239.         lea    a5@(-pr_MsgPort+tc_MemEntry:W),a0
  240.         movel    a2,a1
  241.         jsr    a6@(_LVOAddTail:W)
  242.  
  243. | clear cli_Module to prevent unloading by the shell
  244.  
  245.         clrl    a3@
  246.  
  247. | reenable multitasking - all done or maybe not ...
  248.  
  249. noproc:        jsr    a6@(_LVOPermit:W)
  250.  
  251. | if (a5 != 0) goto skip;
  252.  
  253.         movel    a5,d0
  254.         bnes    nomem
  255.  
  256. | error creating the process - free lock and memory
  257.  
  258.         movel    a4@(_curDir:W),d1
  259.         exg    d6,a6
  260.         jsr    a6@(_LVOUnlock:W)
  261.         exg    d6,a6
  262.  
  263.         movel    a2,a1
  264.         movel    d5,d0
  265.         jsr    a6@(_LVOFreeMem:W)
  266.  
  267. | close dos.library
  268.  
  269. nomem:        movel    d6,a1
  270.         jsr    a6@(_LVOCloseLibrary:W)
  271.  
  272. | exit graceful
  273.  
  274. nodos:        moveq    #RETURN_OK,d0
  275.         rts
  276.  
  277. | data area
  278.  
  279.         .data
  280.  
  281. .lcomm        _SaveSP,4
  282. .lcomm        _curDir,4
  283. .lcomm        _cmdLine,4
  284. .lcomm        _DOSBase,4
  285. .comm        _SysBase,4
  286. .comm        __WBenchMsg,4
  287. .comm        ___commandline,4
  288.